<template>
  <div id="container">
    <div id="amapcontainer" style="width: 2000px; height: 900px">
</div>
<div class="input-container">
    <el-input v-model="input" placeholder="请输入关键字"></el-input>
   </div>
 <div class="icon-container">
  <div class="toilent"> 
    <div class="toilent-img">
     <img src="@/assets/厕所.png">
     <p>厕所</p>
    </div>
  
    
  </div> 
  <!-- <div class="toilent">
     <img src="@/assets/厕所.png"> 
  </div> 
  <div class="toilent">
     <img src="@/assets/厕所.png"> 
  </div> 
  <div class="toilent">
     <img src="@/assets/厕所.png"> 
  </div> 
  <div class="toilent">
     <img src="@/assets/厕所.png"> 
  </div> 
  <div class="toilent">
     <img src="@/assets/厕所.png"> 
  </div> 
  <div class="toilent">
     <img src="@/assets/厕所.png"> 
  </div> 
  <div class="toilent">
     <img src="@/assets/厕所.png"> 
  </div> -->
   
 </div>
  </div>
</template>
<script>
import AMapLoader from '@amap/amap-jsapi-loader';
// window._AMapSecurityConfig = {
//   securityJsCode: 'cb4cdb5c4bf02542adf8fa4899140f13' // '「申请的安全密钥」',
// }
export default {
  data () {
    return {
      input:'',
      map: null,
      markerList: [],
      mapList: [
        {
          name: '小王',
          address: '广东省广州市海珠区',
          lnglats: [106.416048,29.400544]
        }, {
          name: '小张',
          address: '广东省广州市黄埔区',
          lnglats: [106.412632,29.421050]
        }, {
          name: '小李',
          address: '广东省广州市荔湾区',
          lnglats: [106.418020,29.417182]
        },
        {
          name: '小赵',
          address: '广东省广州市天河区',
          lnglats: [106.369173,29.400391]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.436135,29.407462]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.436350,29.410834]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.437154,29.409988]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.365810,29.416076]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.427231,29.434839]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.363585,29.419540]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.361663,29.420388]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.439060,29.428589]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.423601,29.373037]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.440115,29.429505]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.361574,29.387710]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.424214,29.372635]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.354511,29.418883]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.356133,29.397480]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.363385,29.432747]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.435674,29.375373]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.451639,29.411530]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.445053,29.432104]
        },
        {
          name: '厕所',
          address: '九龙坡区',
          lnglats: [106.446934,29.429830]
        },
      ]
    }
  },
  mounted () {
    // DOM初始化完成进行地图初始化
    this.initAMap()
  },
  methods: {
    initAMap () {
      AMapLoader.load({
        key: "7c75098ad49653a19daf84c03fd1365f", // 申请好的Web端开发者Key，首次调用 load 时必填
        version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
        plugins: ["AMap.Scale", "AMap.ToolBar", "AMap.ControlBar", 'AMap.Geocoder', 'AMap.Marker',
          'AMap.CitySearch', 'AMap.Geolocation', 'AMap.AutoComplete', 'AMap.InfoWindow'], // 需要使用的的插件列表，如比例尺'AMap.Scale'等
      }).then((AMap) => {
        // 获取到作为地图容器的DOM元素，创建地图实例
        this.map = new AMap.Map("amapcontainer", { //设置地图容器id
          resizeEnable: true,
           // 地图显示的缩放级别
          viewMode: "3D", // 使用3D视图
          zoomEnable: true, // 地图是否可缩放，默认值为true
          dragEnable: true, // 地图是否可通过鼠标拖拽平移，默认为true
          doubleClickZoom: true, // 地图是否可通过双击鼠标放大地图，默认为true
          zoom: 5, //初始化地图级别
          center: [106.416048, 29.400544], // 初始化中心点坐标 广州
          mapStyle: "amap://styles/graffiti", // 设置颜色底层
          pitch:45
        })
        this.setMapMarker()
      }).catch(e => {
        console.log(e)
      })
    },
    // 增加点标记
    setMapMarker () {
      // 创建 AMap.Icon 实例
      let icon = new window.AMap.Icon({
        size: new window.AMap.Size(36, 36), // 图标尺寸
        image: require('@/assets/农村公厕厕所.png'), // Icon的图像
        imageSize: new window.AMap.Size(24, 30), // 根据所设置的大小拉伸或压缩图片
        imageOffset: new window.AMap.Pixel(0, 0)  // 图像相对展示区域的偏移量，适于雪碧图等
      });
      let makerList = []
      this.mapList.forEach((item) => {
        // 遍历生成多个标记点
        let marker = new window.AMap.Marker({
          map: this.map,
          zIndex: 9999999,
          icon: icon, // 添加 Icon 实例
          offset: new window.AMap.Pixel(-13, -30), //icon中心点的偏移量
          position: item.lnglats // 经纬度对象new AMap.LngLat(x, y)，也可以是经纬度构成的一维数组[116.39, 39.9]
        });
        makerList.push(marker)
      });
      this.map.add(makerList)
      // 自动适应显示想显示的范围区域
      this.map.setFitView();
    },
    
  }
}
</script>

<style>
#container{
  position: relative;
}
.input-container{
  position: absolute;
  top: 100px;
  left: 100px;
}
.icon-container{
  position: absolute;
  top: 800px;
  left: 100px;
  width: 1800px;
  height: 80px;
  background-color: aliceblue;
  opacity: 0.5;
  
}
.toilent{
  position: relative;
  width: 100px;
  height: 115px;
  margin-top: -35px;
  margin-left:70px ;
}
 .toilent-img{
  margin-left: 0px;
  margin-top: 15px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background-color:  blue;
  line-height: 70px;
  opacity: 0.8;
}
 .toilent-img img{
  width: 50px;
  height: 50px;
  margin-left: 10px;
  margin-top: 10px;
}
.toilent p{
 position: absolute;
 left: 20px;
 top: 50px;
}  
</style>